variable name of variable

Hello all (especially @Niel & @Stivejobstan123 & @Camelot)


next question by beginner:


can I ask (and, actually, create) a variable by name in this way:


repeat 3 times

set i to 1

set a( i )to i*6

set i to i+1

end repeat


return a(2)

return a(x) etc.

PS I know about "on something () - end something"

but question about variable

MacBook Pro, OS X El Capitan (10.11.2), null

Posted on Jul 5, 2016 7:25 PM

Reply
2 replies

Jul 5, 2016 11:30 PM in response to sashaosonia

I'm not entirely sure what you hoped your code would do, but if you're asking about creating dynamically named variables, the short answer is no - variables must be defined at compile time and you cannot create dynamic variables at runtime.


The sole(?) exception to this is to create one variable as a list object and populate that with your dynamically-created variables, but that might not fit your needs.

Jul 7, 2016 9:35 AM in response to sashaosonia

Hello


Perhaps what you want is list which is an ordered collection of items.



set a to {} repeat with i from 1 to 3 set a's end to i * 6 end repeat return a --return a's item 2



If you're indeed looking for something like hash table (associative array), you might try the code listed in the following thread.


Set an indeterminate number of variables

https://discussions.apple.com/thread/7000650



Good luck,

H

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

variable name of variable

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.